#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string, int> Map;
int n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    while (n--)
    {
        string s;
        cin >> s;
        Map[s]++;
        if (Map[s] == 1)
            cout << "OK" << endl;
        else
            cout << s << Map[s] - 1 << endl;
    }
    return 0;
}